import com from '../utils/common.js'

export default {
  getCategoryInfo ({ commit }) {
    com.myajax('/sys/dict/listByType', {
      type: 'repair_type'
    }, (data) => {
      data = data.data
      var cate = []
      for (let i = 0; i < data.length; i++) {
        const ele = data[i]
        const imgs = com.getCategoryImg(ele.value)
        var obj = {
          id: ele.id,
          name: ele.value,
          imgsrc: imgs.imgsrc,
          imgsrcset: imgs.imgsrcset
        }
        cate.push(obj)
      }

      commit('set_category_data', cate)
    })
  },
  getBuildingInfo ({ commit }) {
    com.myajax('/sys/dict/listByType', {
      type: 'building'
    }, (data) => {
      data = data.data
      var building = []
      for (let i = 0; i < data.length; i++) {
        const ele = data[i]
        var obj = {
          id: ele.id,
          name: ele.value
        }
        building.push(obj)
      }

      commit('set_building_data', building)
    })
  },
  getOrderDetail ({ commit }) {
    let rid = localStorage.oid
    com.myajax('/sys/userrepair/info', {
      repairId: rid
      // repairNO: '20190101074050504295'
    }, (data) => {
      data = data.userRepair
      commit('set_order_detail', data)
    })
  },
  getHolidays ({ commit }) {
    com.myajax('/userInfo/work/queryLatelyHolidayList', {}, (data) => {
      data = data.holidayList
      let holidays = []
      for (let i = 0; i < data.length; i++) {
        const ele = data[i]
        if (ele.isHoliday === '1') {
          holidays.push({
            day: ele.date.slice(0, 10),
            name: ele.holidayName
          })
        }
      }

      commit('set_holidays', holidays)
    })
  }
}
